package com.newtouch.bxzs.database.controller;

import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import com.newtouch.bxzs.database.config.MyLog;
import com.newtouch.bxzs.database.model.*;
import com.newtouch.bxzs.database.service.OrganizationMappingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 映射机构关系Controller类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020/12/22 14:17</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author lhx
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "映射关系")
@RestController
@RequestMapping("/mappingRelation")
@SuppressWarnings("unchecked")
public class OrganizationMappingController {
    /**
     * 静态变量：系统日志
     */
    private static final Log logger = LogFactory.getLog(OrganizationMappingController.class);

    @Autowired
    private OrganizationMappingService organizationMappingService;

    @ApiOperation(value = "根据机构名称获取机构映射关系列表")
    @PostMapping("/getMappingList")
    @MyLog(systemFunctionName = "映射关系",systemFunctionUrl = "/mappingRelation/getMappingList",userOperationType = 4,userOperationSummary = "查询机构映射关系列表")
    public BaseResponse<OrganizationMapBO> mappingList(@RequestBody OrganizationVO organizationVO) {
        logger.info("根据机构名称查询组织机构映射关系列表");
        return RespGenerator.returnOK(organizationMappingService.getMappingList(organizationVO));

    }

    @ApiOperation(value = "根据用户机构编码获取机构映射关系列表")
    @PostMapping("/getMappingListByCode")
    @MyLog(systemFunctionName = "映射关系",systemFunctionUrl = "/mappingRelation/getMappingListByCode",userOperationType = 4,userOperationSummary = "查询用户所属机构映射关系信息")
    public BaseResponse<OrganizationMapTotalBO> mappingListByCode(@RequestBody OrganizationMapByUserVO organizationMapByUserVO) {
        logger.info("根据用户机构编码获取机构映射关系列表");
        return RespGenerator.returnOK(organizationMappingService.getMappingListByCode(organizationMapByUserVO));
    }

    @ApiOperation(value = "根据主键获取映射机构详情信息")
    @PostMapping("/getOrganizationMappingInfo")
    @MyLog(systemFunctionName = "映射关系",systemFunctionUrl = "/mappingRelation/getOrganizationMappingInfo",userOperationType = 4,userOperationSummary = "查询机构映射关系详情信息")
    public BaseResponse<OrganizationMapBO> organizationMappingInfo(@RequestBody OrganizationMapVO organizationMapVO) {
        logger.info("根据机构主键查询映射机构详情");
        return RespGenerator.returnOK(organizationMappingService.getOrganizationMappingInfo(organizationMapVO.getOrganizationMapId()));
    }

    @ApiOperation(value = "新增或者修改映射机构关系")
    @PostMapping("/modifyMapping")
    @MyLog(systemFunctionName = "映射关系",systemFunctionUrl = "/mappingRelation/modifyMapping",userOperationType = 5,userOperationSummary = "新增或者修改映射机构关系")
    public BaseResponse<OrganizationMapBO> modifyMapping(@RequestBody OrganizationMapModifyVO organizationMapModifyVO) {
        logger.info("新增或者修改映射机构关系信息");
        return RespGenerator.returnOK(organizationMappingService.modifyMapping(organizationMapModifyVO));
    }

    @ApiOperation(value = "根据主键修改映射关系为不可见--删除")
    @PostMapping("/deleteMapping")
    @MyLog(systemFunctionName = "映射关系",systemFunctionUrl = "/mappingRelation/deleteMapping",userOperationType = 3,userOperationSummary = "删除映射机构信息")
    public BaseResponse<OrganizationMapBO> deleteMapping(@RequestBody List<String> organizationMappingIds) {
        logger.info("根据主键修改映射关系为不可见");
        return RespGenerator.returnOK(organizationMappingService.deleteMapping(organizationMappingIds));

    }

    @ApiOperation(value = "根据关系主键修改映射关系状态--启用或者禁用")
    @PostMapping("/modifyMappingState")
    @MyLog(systemFunctionName = "映射关系",systemFunctionUrl = "/mappingRelation/modifyMappingState",userOperationType = 2,userOperationSummary = "修改映射机构关系状态")
    public BaseResponse<OrganizationMapBO> modifyMappingState(@RequestBody OrganizationMapVO organizationMapVO) {
        logger.info("根据关系主键修改映射关系状态");
        return RespGenerator.returnOK(organizationMappingService.modifyMappingState(organizationMapVO));
    }
}
